package com.brspace.qualitycontrol.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.brspace.qualitycontrol.entity.Leaveing;
import com.brspace.qualitycontrol.entity.Letter;
import com.brspace.qualitycontrol.entity.vo.LeaveQueryVo;
import com.brspace.qualitycontrol.entity.vo.LeaveingVo;
import com.brspace.qualitycontrol.entity.vo.LetterQueryVo;
import com.brspace.qualitycontrol.service.LetterService;
import com.brspace.qualitycontrol.service.ProcessNodeService;
import com.brspace.qualitycontrol.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 信访诉求 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-09
 */
@Api(description = "信访诉求")
@CrossOrigin
@RestController
@RequestMapping("/admin/letter")
public class LetterController {
    @Resource
    private LetterService letterService;
    @Resource
    private ProcessNodeService processNodeService;

    /**
     * 信访诉求录入
     * @param letter
     * @return
     */
    @ApiOperation("信访诉求录入")
    @PostMapping("letterAdd")
    public R letterAdd(Letter letter){
        return letterService.add(letter);
    }

    /**
     * 分页列表
     * @param page
     * @param limit
     * @return
     */
    @ApiOperation("分页列表")
    @PostMapping("list/{page}/{limit}")
    public R pageList(
            @ApiParam(value = "当前页码",required = true) @PathVariable Long page,
            @ApiParam(value = "每页多少数据", required = true) @PathVariable Long limit){
        Page<Letter> pageParam = new Page<>(page, limit);
        IPage<Letter> pageModel = letterService.selectPage(pageParam, null);
        List<Letter> records = pageModel.getRecords();
        long total = pageModel.getTotal();
        return R.ok().data("total",total).data("rows",records);
    }

    @ApiOperation("待审批分页列表")
    @PostMapping("list1/{page}/{limit}/{id}")
    public R pageList1(
            @ApiParam(value = "当前页码",required = true) @PathVariable int page,
            @ApiParam(value = "每页多少数据", required = true) @PathVariable int limit,
            @ApiParam(value="用户ID", required = true) @PathVariable String id,
            @ApiParam(value = "待审批查询对象") LetterQueryVo letterQueryVo){
        return letterService.listFind(page,limit, letterQueryVo,id);
    }
    @ApiOperation("已审批分页列表")
    @PostMapping("stateList/{page}/{limit}/{id}")
    public R stateList1(@ApiParam(value = "当前页码",required = true) @PathVariable int page,
                        @ApiParam(value = "每页多少数据", required = true) @PathVariable int limit,
                        @ApiParam(value="用户ID", required = true) @PathVariable String id,
                        @ApiParam(value = "已审批查询对象") LetterQueryVo letterQueryVo){
        return letterService.findList(page,limit, letterQueryVo,id);
    }
    @ApiOperation("全部分页列表")
    @PostMapping("findAll/{page}/{limit}/{id}")
    public R findList(@ApiParam(value = "当前页码",required = true) @PathVariable int page,
                        @ApiParam(value = "每页多少数据", required = true) @PathVariable int limit,
                        @ApiParam(value="用户ID", required = true) @PathVariable String id,
                      @ApiParam(value = "全部查询对象") LetterQueryVo letterQueryVo){
        return letterService.seleAll(page,limit, letterQueryVo,id);
    }

    /**
     * 信访总数  以及折线图
     * @return
     */
    @ApiOperation("信访总数以及信访总数折线图")
    @PostMapping("num")
    public R num(){
        return letterService.num();
    }

    /**
     * 已办总数以及树状图
     * @return
     */
    @ApiOperation("已办总数以及树状图")
    @PostMapping("alreadyNum")
    public R alreadyNum(){
        return letterService.alreadyNum();
    }

    /**
     * 代办总数以及代办树状图
     * @return
     */
    @ApiOperation("代办总数以及代办树状图")
    @PostMapping("waitNum")
    public R waitNum(){
        return letterService.waitNum();
    }

    /**
     * 柱状图
     * @return
     */
    @ApiOperation("办理状态图")
    @PostMapping("stateZhu")
    public R stateZhu(){
        return letterService.stateZhu();
    }

    @ApiOperation("根据ID查询一个")
    @PostMapping("findById/{id}")
    public R findById(@ApiParam(value = "id", required = true) @PathVariable String id){
        return R.ok().data("letter",letterService.findById(id)).data("sort",processNodeService.findLetter(id));
    }


    @ApiOperation("审核")
    @PostMapping("examine/{userName}/{uid}")
    public R examine(
            @ApiParam(value = "下阶段办理人ID" ,required = true) @PathVariable String userName,
            @ApiParam(value = "当前节点办理人ID" , required = true) @PathVariable String uid,
            @ApiParam("对象类型")   Letter letter){
        return letterService.examine(letter,userName,uid);
    }
}

